package main

import (
	"12.2-gokit/Services/UserEndpoint"
	"12.2-gokit/Services/UserService"
	"12.2-gokit/Services/UserTransport"
	"12.2-gokit/util"
	httptransport "github.com/go-kit/kit/transport/http"
	"github.com/gorilla/mux"
	_ "github.com/jinzhu/gorm"
	"net/http"
)
import _ "github.com/go-sql-driver/mysql"

func main()  {

	//Dao.InitDatabase()
	//db := Dao.Databasemysql.Db
	//db.Close()
	//User := UserService.UserService{}
	//
	//serverHandler := httpkit.NewServer(UserEndpoint.GenUserEndpoint(User), UserTransport.DecodeUserRequest, UserTransport.EncodeUserResponse)
	//r := mux.NewRouter()
	//r.Handle("/user/{uid:[0-9]+}", serverHandler)
	//
	//http.ListenAndServe(":8088", r)

	user := UserService.UserService{}
	endp := UserEndpoint.GenUserEndpoint(user)

	serverHandler := httptransport.NewServer(endp, UserTransport.DecodeUserRequest, UserTransport.EncodeUserResponse)

	r := mux.NewRouter()
	r.Methods("GET").Path("/user/{uid:\\d+}").Handler(serverHandler)
	r.Methods("GET").Path("/health").HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
		//vars := mux.Vars(request)
		writer.Header().Set("Content-type", "application/json")
		writer.Write([]byte(`{"status":"ok"}`))
	})
	util.RegService()
	http.ListenAndServe(":8088", r)
}
